/**
 * MiniGolf Scorecard
 * Copyright (C) 2010  MiriTheQuiet, http://minigolfscorecard.googlecode.com/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.mtq.mgsc;

import javax.microedition.lcdui.Font;

import cz.mtq.mgsc.resources.ResourceBundleCache;

public final class Settings {

	public static final int MAX_NAME_LENGTH = 6;

	private static int NAME_CELL_WIDTH;
	private static int HOLE_CELL_WIDTH;
	private static int CELL_HEIGHT;
	private static int ONE_DIGIT_MARGIN;
	private static int TWO_DIGIT_MARGIN;
	private static int CHAR_WIDTH;

	public static final String TEXT_APP_NAME = "app_name";
	public static final String TEXT_PLAY = "play";
	public static final String TEXT_EXIT = "exit";
	public static final String TEXT_NUMBER_OF_PLAYERS = "num_of_players";
	public static final String TEXT_PLAYERS_NAME = "player_name";
	public static final String TEXT_MODE = "mode";
	public static final String TEXT_LANGUAGE = "lang";
	public static final String TEXT_MAIN_MODE = "standard_mode";
	public static final String TEXT_END_OF_THE_GAME_MODE = "end_of_game_mode";
	public static final String TEXT_YES = "yes";
	public static final String TEXT_NO = "no";
	public static final String TEXT_EXIT_CONFIRM = "exit_confirm";

	private static final ResourceBundleCache resourceBundleCache = new ResourceBundleCache();

	private Settings() {
	}

	/**
	 * 
	 * @param midlet
	 * @return locale
	 *         TODO implement reading default locale from record store
	 */
	public static String getDefaultLocale(MgscMidlet midlet) {
		return "cs";
	}

	public static void setResoureBundleLocale(String locale) {
//		try {
//			UIManager.getInstance().setResourceBundle(Resources.open("/messages.res").getL10N("messages", locale));
//		} catch (IOException e) {
//			throw new RuntimeException(e.getMessage());
//		}
		resourceBundleCache.initCurrentBundle(locale);
	}

	public static String getResource(String key) {
		// return (String) UIManager.getInstance().getResourceBundle().get(key);
		return resourceBundleCache.getCurrentBundle().getString(key);
	}

	public static void clearResourceBundleCache(){
		resourceBundleCache.removeResourceBundlesExceptCurrentFromCache();
	}
	
	/**
	 * Initialize cells (name and hole cell) width and height
	 * 
	 * @param font
	 */
	public static void initCellSize(Font font) {
		CHAR_WIDTH = font.stringWidth("X");
		NAME_CELL_WIDTH = MAX_NAME_LENGTH * CHAR_WIDTH;
		HOLE_CELL_WIDTH = 2 * CHAR_WIDTH + CHAR_WIDTH / 2;
		TWO_DIGIT_MARGIN = CHAR_WIDTH / 4;
		ONE_DIGIT_MARGIN = 3 * CHAR_WIDTH / 4;// TWO_DIGIT_MARGIN + CHAR_WIDTH / 2;
		CELL_HEIGHT = font.getHeight();
	}

	public static int getNAME_CELL_WIDTH() {
		return NAME_CELL_WIDTH;
	}

	public static int getHOLE_CELL_WIDTH() {
		return HOLE_CELL_WIDTH;
	}

	public static int getCELL_HEIGHT() {
		return CELL_HEIGHT;
	}

	public static int getONE_DIGIT_MARGIN() {
		return ONE_DIGIT_MARGIN;
	}

	public static int getCHAR_WIDTH() {
		return CHAR_WIDTH;
	}

	public static int getTWO_DIGIT_MARGIN() {
		return TWO_DIGIT_MARGIN;
	};

}
